// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-21 20:19
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.DateTrain;

public class ToGoatLatin {
    // 山羊拉丁文，简单模拟
    public String toGoatLatin(String sentence) {
        String[] words = sentence.split(" ");
        StringBuilder ans = new StringBuilder();

        for (int i = 0; i < words.length; i++) {
            StringBuilder tmp = new StringBuilder();
            // 首字母是元音字母
            if (isNotVow(words[i].charAt(0))) {
                int start = Math.min(1, words[i].length()-1);
                tmp.append(words[i].substring(start, words[i].length())).append(words[i].charAt(0));
            } else {
                tmp.append(words[i]);
            }
            tmp.append("ma");
            for (int j = 0; j < i + 1; j++) {
                tmp.append('a');
            }
            ans.append(tmp).append(" ");
        }
        return ans.toString().substring(0, ans.length() - 1);
    }

    private boolean isNotVow(char c) {
        return c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u' && c != 'A' && c != 'E' && c != 'I' && c != 'O' && c != 'U';
    }
}
